package cn.kuang.controller;

import cn.kuang.pojo.Route;
import cn.kuang.service.RouteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 徽州大都督
 * @date 2020/7/27
 */
@RestController
@RequestMapping("route")
public class RouteController {

    @Autowired
    private RouteService routeService;
    @Autowired
    private RedisTemplate redisTemplate;

    @GetMapping("findPage/{page}/{size}/{cid}")
    public List<Route> findPage(@PathVariable("page")Integer page,@PathVariable("size")Integer size,@PathVariable("cid")String c){
        //System.out.println (page);
        //System.out.println (size);
        //System.out.println (cid);
        Integer cid = Integer.parseInt (c);

        return routeService.findPage(page,size,cid);

        //return null;
    }

    @GetMapping("findByRid/{rid}")
    public Route findByRid(@PathVariable("rid")Integer rid){

        //System.out.println (rid);

        return routeService.findByRid(rid);

    }

    /**
     * 收藏
     * @param username
     * @param rid
     * @return
     */
    @PostMapping("collection/{username}/{rid}")
    public String collection(@PathVariable("username")String username,@PathVariable("rid")Integer rid){
        //System.out.println (username);
        //System.out.println (rid);
        String msg = routeService.collection (username, rid);

        return msg;
    }

    @PostMapping("findPage/{page}/{size}/{username}")
    public List<Route> findByPage(@PathVariable("page")Integer page,@PathVariable("size")Integer size,@PathVariable("username")String username){
        //System.out.println (page);
        //System.out.println (size);
        //System.out.println (username);
        //routeList.forEach (System.out::println);
        //System.out.println ("访问了");

        List<Route> byPage = routeService.findByPage (page, size, username);

        return byPage;

    }


    @PostMapping("findByRname/{page}/{size}/{rname}")
    public List<Route> findByRname(@PathVariable("page")Integer page,@PathVariable("size")Integer size,@PathVariable("rname")String rname){
        /*System.out.println (page);
        System.out.println (size);
        System.out.println (rname);*/
        //routeList.forEach (System.out::println);


        List<Route> routeList = routeService.findByRname (page, size, rname);

        return routeList;

    }

}
